import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xiaomi_shop/app/api/api.dart';
import 'package:xiaomi_shop/app/modules/cart/controllers/cart_controller.dart';
import 'package:xiaomi_shop/app/services/screenAdapter.dart';
import 'package:xiaomi_shop/models/index.dart';

class CartItemViewView extends GetView {
  ShopModel model;
  CartItemViewView(this.model, {super.key});
  @override
  Widget build(BuildContext context) {
    return GetBuilder<CartController>(
      builder: (controller) {
        return Container(
          padding: EdgeInsets.all(ScreenAdapter.width(20)),
          margin: EdgeInsets.only(bottom: ScreenAdapter.width(20)),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(ScreenAdapter.width(16)),
          ),
          child: Row(
            children: [
              SizedBox(
                  width: ScreenAdapter.width(100),
                  child: Checkbox(
                      activeColor: Colors.red,
                      shape: CircleBorder(
                          side: BorderSide(color: Colors.grey.shade100)),
                      value: model.selected,
                      onChanged: (selected) {
                        print(selected);
                        model.selected = selected!;
                        controller.isCheckAll();
                        controller.calculatePrice();
                      })),
              Container(
                padding: EdgeInsets.fromLTRB(0, ScreenAdapter.width(20),
                    ScreenAdapter.width(20), ScreenAdapter.width(20)),
                width: ScreenAdapter.width(340),
                child: Image.network("${Api.basicUrl}/${model.pic}"),
              ),
              Expanded(
                  child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    model.title!,
                    style: TextStyle(
                        fontSize: ScreenAdapter.fontSize(40),
                        fontWeight: FontWeight.bold,
                        overflow: TextOverflow.ellipsis),
                    maxLines: 2,
                  ),
                  SizedBox(
                    height: ScreenAdapter.height(10),
                  ),
                  Text(
                    model.sub_title!,
                    style: TextStyle(
                        color: Colors.black45,
                        fontSize: ScreenAdapter.fontSize(30),
                        overflow: TextOverflow.ellipsis),
                    maxLines: 2,
                  ),
                  SizedBox(
                    height: ScreenAdapter.height(20),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '¥ ${model.price}',
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                      ),
                      Container(
                        width: ScreenAdapter.width(300),
                        height: ScreenAdapter.height(80),
                        decoration: BoxDecoration(
                            borderRadius:
                                BorderRadius.circular(ScreenAdapter.height(40)),
                            border: Border.all(color: Colors.grey.shade400)),
                        child: Row(
                          children: [
                            SizedBox(
                              width: ScreenAdapter.height(80),
                              height: ScreenAdapter.height(100),
                              child: IconButton(
                                  padding: EdgeInsets.zero,
                                  onPressed: () {
                                    if (model.buyNumber > 1) {
                                      model.buyNumber--;
                                      print(model.buyNumber);
                                      controller.calculatePrice();
                                    }
                                  },
                                  icon: const Icon(Icons.remove)),
                            ),
                            Expanded(
                                child: Container(
                              decoration: BoxDecoration(
                                  border: Border(
                                      left: BorderSide(
                                          color: Colors.grey.shade400),
                                      right: BorderSide(
                                          color: Colors.grey.shade400))),
                              child: Text(
                                "${model.buyNumber}",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                    fontSize: ScreenAdapter.fontSize(40)),
                              ),
                            )),
                            SizedBox(
                              width: ScreenAdapter.height(80),
                              height: ScreenAdapter.height(100),
                              child: IconButton(
                                  padding: EdgeInsets.zero,
                                  onPressed: () {
                                    if (model.buyNumber < 99) {
                                      model.buyNumber++;
                                      print(model.buyNumber);
                                      controller.calculatePrice();
                                    }
                                  },
                                  icon: const Icon(Icons.add)),
                            )
                          ],
                        ),
                      ),
                    ],
                  ),
                ],
              ))
            ],
          ),
        );
      },
    );
  }
}
